<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<!-- 删除按钮 -->
			<cl-multi-delete-btn />
			<cl-flex1 />
			<cl-filter label="是否显示该游戏1">
				<cl-select :options="options.game_show" prop="gender" style="width: 120px" />
			</cl-filter>
			<!-- 关键字搜索 -->
			<cl-search-key />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" name="wx_game-game_info" setup>
import { reactive } from "vue";
import { useCrud, useTable, useUpsert } from "@cool-vue/crud";
import { useCool } from "/@/cool";

const { service } = useCool();

// cl-upsert
const Upsert = useUpsert({
	items: [
		{ prop: "title", label: "游戏名称", required: true, component: { name: "el-input" } },
		{
			prop: "price",
			label: "所需积分",
			hook: { bind: ["number"] },
			component: { name: "el-input-number", props: { min: 0 } },
			required: true
		},
		{ prop: "description", label: "游戏描述", component: { name: "el-input" } },
		{ prop: "main_image", label: "主图", component: { name: "cl-upload" }, required: true },
		{
			prop: "example_images",
			label: "示例图",
			component: { name: "cl-upload", props: { multiple: true } },
			required: true
		},
		{ prop: "game_key", label: "游戏key", required: true, component: { name: "el-input" } },
		{
			prop: "game_show",
			label: "是否显示该游戏",
			required: true,
			component: { name: "el-input" }
		}
	]
});

// cl-table
const Table = useTable({
	columns: [
		{ type: "selection" },
		{ prop: "id", label: "ID" },
		{ prop: "title", label: "游戏名称" },
		{ prop: "price", label: "所需积分" },
		{ prop: "description", label: "游戏描述" },
		{ prop: "main_image", label: "主图", component: { name: "cl-image", props: { size: 60 } } },
		{
			prop: "example_images",
			label: "示例图",
			component: { name: "cl-image", props: { size: 60 } }
		},
		{ prop: "game_key", label: "游戏key" },
		{ prop: "game_show", label: "是否显示该游戏" },
		{ prop: "createTime", label: "创建时间", sortable: "desc", width: 160 },
		{ prop: "updateTime", label: "更新时间", sortable: "custom", width: 160 },
		{ type: "op", buttons: ["edit", "delete"] }
	]
});

// 数据选项
const options = reactive({
	game_show: [
		{
			label: "不显示",
			value: 0
		},
		{
			label: "显示",
			value: 1
		}
	]
});
// cl-crud
const Crud = useCrud(
	{
		service: service.wx_game.game_info
	},
	(app) => {
		app.refresh();
	}
);
</script>
